//
//  File.swift
//
//
//  Created by didi on 2022/9/7.
//

import Fluent
import Vapor

public protocol MolecularDatabaseModel: Model where Self.IDValue == UUID {
    associatedtype From: MolecularModule

    /// unique key for the database model
    static var uniqueKey: String { get }

    /// unique identifier of the database model
    var uuid: UUID { get }
}

public extension MolecularDatabaseModel {
    static var schema: String { From.uniqueKey + "_" + uniqueKey }

    static var uniqueKey: String {
        String(describing: self).dropFirst(From.uniqueKey.count).dropLast(5).lowercased() + "s"
    }

    var uuid: UUID { id! }
}
